<%--
  - Author		:	Jaewon Choi
  - Date			:
  - Description	:	
  --%>
<%@ page language="java" %>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/pages/includes/taglibs.jspf" %>
<%@ include file="/WEB-INF/pages/includes/variables.jspf" %>
<%@ include file="/WEB-INF/pages/includes/doctype.jspf" %>
<html>
	<head>
<%@ include file="/WEB-INF/pages/includes/metatags.jspf" %>
		<title><fmt:message key="pages.title" /></title>
		<link rel="stylesheet" type="text/css" href="<c:url value="${dirStyles}/common.css" />" />
		<link rel="stylesheet" type="text/css" href="<c:url value="${dirScripts}/jqueryUi/css/ui-lightness/jquery-ui-1.8.21.custom.css" />" />

		<script type="text/javascript" src="<c:url value="${dirScripts}/common.js" />"></script>
		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-1.7.2.min.js" />"></script>
		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-ui-1.8.21.custom.min.js" />"></script>
		<script type="text/javascript">
			$(function() {
				$( ".date" ).datepicker({
					showOn: "both",
					buttonImage: "<c:url value="${dirImages}/calendar.png" />",
					buttonImageOnly: true,
					dateFormat: "yy-mm-dd"
				});
			});
			function goAction(idx){
				if(idx == "" || ! idx){
					return false;
				}
				document.frm.idx.value= idx;
				document.frm.submit();
			}
			
			function goPage(page){
				document.searchFrm.page.value = page;
				document.searchFrm.submit();
			}
			
			function setIsMain(settingFlag){
				if(settingFlag){
					if(confirm('긴급공지를 설정 하시겠습니까?')){
						var loc = "<c:url value="/notice/setIsMain.do" />?fAct=remove";
						if($(".isMainIdx:checked").length == 1){
							loc += "&idx="+$(".isMainIdx:checked").val();
						}else{
							alert("긴급공지를 선택 해주세요.");
							return;	
						}
						window.location.href=loc;
					}	
				}else{
					if(confirm('긴급공지를 해제 하시겠습니까?')){
						var loc = "<c:url value="/notice/setIsMain.do" />?fAct=remove";
						window.location.href=loc;
					}
				}
			}
		</script>
	</head>
	<body>
		<div class="bodyWrap">
<%@ include file="/WEB-INF/pages/includes/header.jsp" %>
<%@ include file="/WEB-INF/pages/includes/left.jsp" %>
			<div class="contWrap">
				<div class="menuTitle">공지사항</div>
				<div class="searchWrap">
					<form name="searchFrm" action="<c:url value="/notice/list.do" />" method="post">
						<input type="hidden" name="maxnum" value="${maxnum}" />
						<input type="hidden" name="page" value="${page}" />
						<ul  class="lineBlock">
							<li>
								<font>기간</font>
								<input type="checkbox" name="searchDate" value="1" onclick="javascript:$('.date').attr('disabled', !this.checked);" <c:if test="${param.searchDate eq 1}"> checked="checked" </c:if>>
								<input type="text" class="date" name="beginTime" readonly="readonly" value="${param.beginTime}" <c:if test="${param.searchDate ne 1}"> disabled="disabled" </c:if> /> ~ <input type="text" class="date" name="endTime" readonly="readonly" value="${param.endTime}" <c:if test="${param.searchDate ne 1}"> disabled="disabled" </c:if> />
							</li>
							<li>
								<font>브랜드</font>
								<select name="categoryIdx">
									<option value="">전체</option>
									<c:forEach var="category" items="${categoryList}">
										<option value="${category.idx}" <c:if test="${param.categoryIdx eq category.idx}"> selected="selected" </c:if>>${category.name}</option>
									</c:forEach>
								</select>
							</li>							
						</ul>
						<input class="btn" type="submit" value="검색" onclick="javascript:document.searchFrm.page.value=1;" />
					</form>
					<!-- 
					<div style="text-align: right;">
						<input type="button" class="btn" value="등록" onclick="javascript:location.href='<c:url value="/notice/form.do" />';" />
					</div>
					 -->
				</div>
				<form name="removeFrm" method="post" action="<c:url value="/notice/remove.do" />">
					<input type="hidden" name="maxnum" value="${maxnum}" />
					<input type="hidden" name="page" value="${page}" />
					<input type="hidden" name="searchDate" value="${param.searchDate}">
					<input type="hidden" name="beginTime" value="${param.beginTime}" /> 
					<input type="hidden" name="endTime" value="${param.endTime}" />
					<input type="hidden" name="fAct" value="remove">
					<table class="listTbl">
						<colgroup>
							<col width="35px;" />
							<col width="35px;" />
							<col width="90px" />
							<col width="*" />
							<col width="180px" />
							<col width="90px" />
							<col width="90px" />
							<!-- 
							<col width="90px" />
							 -->
						</colgroup>
						<thead>
							<tr>
								<th><input type="checkbox" onclick="javascript:$('.removeChk').attr('checked', $(this).is(':checked')?true:false);"></th>
								<th>No.</th>
								<th>브랜드</th>
								<th>제목</th>
								<th>기간</th>
								<th>등록일시</th>
								<th>최종수정일시</th>
								<!-- 
								<th>긴급공지</th>
								 -->
							</tr>
						</thead>
						<c:choose>
							<c:when test="${noticeListTotalCnt ne 0}">
								<tbody>
									<c:forEach items="${noticeList}" var="notice" varStatus="noticeStat">
										<tr class="dataTr">
											<td>
												<input type="checkbox" name="idx" class="removeChk" value="${notice.idx}">
											</td>											
											<td>${noticeListTotalCnt - noticeStat.index - (maxnum*(page-1))}</td>
											<td onclick="javascript:goAction(${notice.idx});">
												<c:out value="${notice.categoryNm}" />
											</td>
											<td onclick="javascript:goAction(${notice.idx});" style="text-align: left; text-indent: 15px;">
												<c:choose>
													<c:when test="${fn:length(notice.title) > 22}">
														<c:out value="${fn:substring(notice.title, 0, 22)}" />...
													</c:when>
													<c:otherwise>
														<c:out value="${notice.title}" />
													</c:otherwise>
												</c:choose>
											</td>											
											<td onclick="javascript:goAction(${notice.idx});">
												<c:choose>
													<c:when test="${not empty notice.beginTime and not empty notice.endTime}">
														<c:catch var="e">
															<fmt:parseDate var="beginTime" pattern="yyyy-MM-dd HH:mm:ss" value="${notice.beginTime}" />
															<fmt:formatDate value="${beginTime}" pattern="yyyy-MM-dd" />
														</c:catch>
														<c:if test="${not empty e}">
															${notice.beginTime}
														</c:if>
														~
														<c:catch var="e">
															<fmt:parseDate var="endTime" pattern="yyyy-MM-dd HH:mm:ss" value="${notice.endTime}" />
															<fmt:formatDate value="${endTime}" pattern="yyyy-MM-dd" />
														</c:catch>
														<c:if test="${not empty e}">
															${notice.endTime}
														</c:if>
													</c:when>
													<c:otherwise>
														항상
													</c:otherwise>
												</c:choose>
											</td>
											<td onclick="javascript:goAction(${notice.idx});">
												<c:catch var="e">
													<fmt:parseDate var="createdTime" pattern="yyyy-MM-dd HH:mm:ss" value="${notice.createdTime}" />
													<fmt:formatDate value="${createdTime}" pattern="yyyy-MM-dd" />
												</c:catch>
												<c:if test="${not empty e}">
													${notice.createdTime}
												</c:if>
											</td>
											<td onclick="javascript:goAction(${notice.idx});">
												<c:catch var="e">
													<fmt:parseDate var="modifiedTime" pattern="yyyy-MM-dd HH:mm:ss" value="${notice.modifiedTime}" />
													<fmt:formatDate value="${modifiedTime}" pattern="yyyy-MM-dd" />
												</c:catch>
												<c:if test="${not empty e}">
													${notice.modifiedTime}
												</c:if>
											</td>
											<!-- 
											<td>
												<input type="radio" class="isMainIdx" name="isMainIdx" value="${notice.idx}"  <c:if test="${notice.isMain eq 1}"> checked="checked" </c:if>>
											</td>
											 -->
										</tr>
									</c:forEach>
								</tbody>
							</c:when>
							<c:otherwise>
								<tfoot>
									<tr><td colspan="8" style="text-align: center;">데이터가 없습니다.</td></tr>
								</tfoot>
							</c:otherwise>
						</c:choose>
					</table>
					<c:if test="${noticeListTotalCnt ne 0}">
						<div class="pagingWrap">
							<jsp:include page="/WEB-INF/pages/includes/paging.jsp">
								<jsp:param name="totalNum" value="${noticeListTotalCnt}" />
								<jsp:param name="pageListCnt" value="${maxnum}" />
								<jsp:param name="pageGrpCnt" value="5" />
								<jsp:param name="pageIdx" value="${page}" />
							</jsp:include>
						</div>
					</c:if>
					<input type="button" class="btn" value="삭제" onclick="javascript:if(confirm('선택하신 목록을 삭제하시겠습니까?')){document.removeFrm.submit();}" />
					<input type="button" class="btn" value="등록" onclick="javascript:location.href='<c:url value="/notice/form.do" />';" />
					<!-- 
					<input type="button" class="btn" value="긴급공지 설정" onclick="javascript:setIsMain(1);" />
					<input type="button" class="btn" value="긴급공지 해제" onclick="javascript:setIsMain(0);" />
					 -->
				</form>
				<form name="frm" action="<c:url value="/notice/detail.do" />" method="post" style="display: none;">
					<input type="hidden" name="idx" value="">
					<input type="hidden" name="maxnum" value="${maxnum}" />
					<input type="hidden" name="page" value="${page}" />
					<input type="hidden" name="searchDate" value="${param.searchDate}">
					<input type="hidden" name="searchBeginTime" value="${param.beginTime}" /> 
					<input type="hidden" name="searchEndTime" value="${param.endTime}" />
				</form>
			</div>
<%@ include file="/WEB-INF/pages/includes/footer.jsp" %>
		</div>
	</body>
</html> 